package com.heima.schedule.feign;

import com.heima.feign.schedule.IScheduleClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.schedule.dtos.TaskDto;
import com.heima.schedule.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ScheduleClient implements IScheduleClient{
    @Autowired
    private TaskService taskService;

    /**
     * 添加任务
     *
     * @param dto
     */
    @PostMapping("/api/v1/task/add")
    @Override
    public ResponseResult addTask(@RequestBody TaskDto dto) {
        return ResponseResult.okResult(taskService.addTask(dto));
    }

    /**
     * 按照类型和优先级拉去任务
     *
     * @param type
     * @param priority
     */
    @GetMapping("/api/v1/task/poll/{type}/{priority}")
    @Override
    public ResponseResult poll(@PathVariable("type") Integer type, @PathVariable("priority") Integer priority) {
        return ResponseResult.okResult(taskService.poll(type,priority));
    }
}
